A production case study on moving beyond Excel spreadsheets and WhatsApp dispatching using Python, Google OR-Tools, and OpenStreetMap.
Every morning at 6:30 AM, dispatch managers at regional delivery hubs face the same high-stakes puzzle:
Dozens of customer orders are waiting, delivery trucks are idling at the loading dock, and drivers are anxious to hit the road. In fleets with 15 to 25 vehicles, dispatching is almost always managed through a stressful combination of tribal knowledge, Excel spreadsheets, and WhatsApp messages.
The result?
Trucks leave the depot half-empty because human dispatchers cannot mentally compute 3D capacity math across 50+ drop-offs.
Oversized orders get delayed because nobody knows how to cleanly split a delivery between trips without sending two drivers to the same place by mistake.
Multi-purpose tasks (like dropping off inventory and collecting payments) get scheduled as separate trips, doubling fuel spend.
We built an Automated Route Optimization & Dispatch Engine in Python designed specifically to eliminate this chaos. Below is a real-world look at how the system works, the real JSON payload driving it, and how it handles complex operational rules—including automatic split deliveries, multi-purpose visits, and live interactive mapping.
The Real-World Constraints: Why Basic Routing Apps Fail
Most off-the-shelf routing tools assume an idealized world: every vehicle is identical, every customer gets a small box, and drivers only do one thing.
In regional supply chains (e.g., agricultural inputs, FMCG, retail distribution), reality looks very different:
1. Orders Larger Than Truck Capacity: If a retail customer orders 5,000 kg of stock, but your largest truck only holds 3,250 kg, what happens? The system cannot reject the order—it must automatically split it into Trip 1 (100% capacity) and Trip 2 (balance) without human intervention.
2. Multi-Purpose Visits: Drivers often deliver stock and perform a second action at the same stop— such as cash collection or quality inspection. Routing algorithms must account for these combined duties at a single stop so drivers aren’t sent back twice.
3. Fleet Cost Arbitrage: Not all vehicles cost the same to run. Some vehicles cost ₨25/km, while others cost ₨30/km. An intelligent solver prioritizes lower-cost assets before mobilizing more expensive vehicles.
1. The Input: Clean, Structured Dispatch Job
Instead of spending two hours manually clustering drop-off notes, the dispatcher feeds a single structured JSON request to our API endpoint.
Here is the exact request from our agricultural distribution hub in Punjab:
{
"warehouse": {
"name": "Warehouse (Bhawan)",
"lat": 31.522334,
"lon": 72.576500
},
"locations": [
{
"name": "Samron Wala Ada",
"lat": 31.3678611,
"lon": 72.6361944,
"visits": [
{ "visit_type": "stock_delivery", "demand_kgs": 5000 },
{ "visit_type": "cash_collection" }
]
},
{
"name": "KD Ada Gagh Chowk",
"lat": 31.43111111111111,
"lon": 72.74569444444444,
"visits": [
{ "visit_type": "stock_delivery", "demand_kgs": 2000 },
{ "visit_type": "inspection" }
]
}
],
"vehicles": [
{
"name": "Shehzor Owned Vehicle #3003",
"trip": 2,
"capacity": 3250,
"fixed_cost": 0.0,
"cost_per_km": 25,
"avg_speed": 45.0
},
{
"name": "Shehzor Owned Vehicle #1111",
"count": 2,
"capacity": 3250,
"fixed_cost": 0.0,
"cost_per_km": 30,
"avg_speed": 45.0
}
]
}Notice what is happening here:
The Customer at Samron Wala Ada needs 5,000 kg of product plus a cash collection.
Each Shehzor truck only has a 3,250 kg limit.
Vehicle #3003 is cheaper (₨25/km) than Vehicle #1111 (₨30/km).
2. The Engine: Mathematical Optimization Under Real Road Speeds
Once submitted, the engine executes a three-phase pipeline in less than 3 seconds:
1. Geospatial Distance Matrix (OSRM): Rather than using flawed straight-line formulas, the system queries a self-hosted OpenStreetMap engine to calculate exact road distances and drive times between all depot and delivery coordinates.
2. Constraint Formulation (Google OR-Tools): The problem is translated into a Time-Bounded Capacitated Vehicle Routing Problem (CVRP) with multi-dimensional dimensions (Weight Capacity, Driver Operating Windows, and Vehicle Cost Functions).
3. Metaheuristic Search: Using Guided Local Search, the solver evaluates thousands of route permutations to find the lowest-cost assignment.
3. The Output: Automated Decision Making & Split Deliveries
Here is what the optimization engine returns:
{
"summary": {
"locations_served": 3,
"vehicles_used": 3,
"total_demand_kgs": 7002,
"total_distance_km": 146.6,
"total_time_hours": 5.8,
"total_cost": 3906
},
"routes": [
{
"vehicle": "Shehzor Owned Vehicle #3003 #1",
"distance_km": 49.3,
"load_kg": 3250,
"load_percent": "100.0%",
"cost": 1231,
"stops": [
{
"location": "Samron Wala Ada (Trip 1/2)",
"demand_kgs": 3250,
"visit_types": ["Stock Delivery", "Cash Collection"] }
]
},
{
"vehicle": "Shehzor Owned Vehicle #3003 #2",
"distance_km": 49.3,
"load_kg": 1751,
"load_percent": "53.9%",
"cost": 1231,
"stops": [
{
"location": "Samron Wala Ada (Trip 2/2)",
"demand_kgs": 1751,
"visit_types": ["Stock Delivery"]
}
]
},
{
"vehicle": "Shehzor Owned Vehicle #1111 #1",
"distance_km": 48.1,
"load_kg": 2001,
"load_percent": "61.6%",
"cost": 1443,
"stops": [
{
"location": "KD Ada Gagh Chowk",
"demand_kgs": 2001,
"visit_types": ["Stock Delivery", "Inspection"]
}
]
}
]
}Key Breakthroughs the Solver Solved Automatically:
1. Intelligent Payload Maxing: Trip 1 of Vehicle #3003 runs at 100.0% capacity (3,250 kg), maximizing transport density.
2. Automated Split Delivery: The 5,000 kg demand at Samron Wala Ada was seamlessly partitioned into Trip 1 (3,250 kg) and Trip 2 (1,751 kg). The cash collection was batched into Trip 1, ensuring the driver only conducts the administrative task once.
3. Cost Prioritization: The solver assigned both available trips of the cheaper vehicle (#3003 @ ₨25/km) before allocating the remaining demand to the higher-cost vehicle (#1111 @ ₨30/km).
4. Visual Verification: Dispatchers Need Maps, Not Just JSON
In real-world logistics, drivers and warehouse supervisors won’t read JSON or complex terminal outputs. They need instant visual clarity.
Our engine compiles the route geometry directly into an interactive Leaflet map that operators can inspect in their dashboard or browser:
(You can open [route_map.html](file:///g:/Github/Route%20Optimization/route_map.html) directly in any browser to zoom in, click stops, inspect driver popups, and toggle route layers).
For web embeds (WordPress, Webflow, or custom dashboards), the engine produces an embeddable iframe snippet:
<iframe
src="route_map.html"
width="100%"
height="500px"
style="border: 1px solid #ddd; border-radius: 8px;"
loading="lazy">
</iframe>┌────────────────────────────────────────────────────────────────────────┐
│ ️ INTERACTIVE DISPATCH SUMMARY │
├────────────────────────────────────────────────────────────────────────┤
│ [🏭 Depot: Bhawan] ──(49 km)──> [📍 Stop 1: Samron Wala Ada (Trip 1)] │
│ • Vehicle: Shehzor #3003 (Route 1 – Red Polyline) │
│ • Load: 3,250 kg (100% Full) | ⏱️ Unloading: 20 mins │
│ │
│ [🏭 Depot: Bhawan] ──(49 km)──> [📍 Stop 2: Samron Wala Ada (Trip 2)] │
│ • Vehicle: Shehzor #3003 (Route 2 – Blue Dashed Polyline) │
│ • Load: 1,751 kg (Balance) │
│ │
│ [🏭 Depot: Bhawan] ──(48 km)──> [📍 Stop 3: KD Ada Gagh Chowk] │
│ • Vehicle: Shehzor #1111 (Route 3 – Green Line) │
│ • Load: 2,001 kg | Inspection + Stock Delivery │
│ │
│ ⚠️ Alert: Split Deliveries Detected & Visualized │
│ 📊 Total Fleet Cost: Rs3,906 | Total Distance: 146.6 km │
└────────────────────────────────────────────────────────────────────────┘
Along with the interactive web map, the engine automatically compiles three ready-to-print Excel sheets:
Sheet 1 (Global Summary): High-level KPIs (Total distance, total bags, vehicle utilization, total cost).
Sheet 2 (Fleet Summary): Breakdown of each vehicle’s assigned operating hours and assigned capacity.
Sheet 3 (Turn-by-Turn Manifest): Driver drop-off sheets with exact arrival order, unloading durations, and payment collection tags.
5. The Bottom-Line Impact for a 15–25 Fleet Operation
When regional logistics companies switch from manual whiteboards to automated dispatch solvers, the financial ROI is immediate:
| Metric | Before (Manual Dispatch) | After (Automated Solver) | Monthly Impact |
| Morning Planning Time | 90–120 minutes | < 30 seconds | Saves ~50 dispatcher hours/month |
| Fleet Capacity Utilization | 60% – 70% | 85% – 95% | Dispatches 2–3 fewer trucks daily |
| Average Daily Mileage | 120 km / truck | 98 km / truck | ~20 km saved per truck / day |
| Driver Overtime Disputes | Frequent (unbalanced shifts) | Near Zero (strict 8h time bounds) | Higher driver retention |
For a fleet of 20 delivery vehicles, saving just 20 km per truck per day equals 400 km of unnecessary driving eliminated every single day. In fuel and maintenance alone, that translates directly to thousands of dollars in pure bottom-line savings every month.
Ready to Automate Your Fleet Dispatch?
If you run a distribution center, regional freight operation, or delivery fleet with 15 to 30 vehicles, you don’t need to buy bloated enterprise software or keep wasting hours on manual spreadsheets.
How We Can Help Your Operation:
1. Free Fleet Route Audit: Send us an anonymized sample of your historical delivery addresses and vehicle capacities. We will run it through our solver and show you exactly how many kilometers, trips, and dollars you could have saved.
2. Turnkey Deployment: We deploy our complete self-hosted Docker engine (OSRM road engine + OR-Tools solver + Leaflet maps + Excel reporting) directly into your private server or cloud.
3. Custom Integration: Need integration with your existing ERP, order management system, or driver GPS trackers? We build custom dispatch APIs tailored to your exact operational workflows.
Ready to see what optimized routing looks like for your fleet? Reach out today to schedule a 30-minute demonstration.

Leave a Reply