Overview

This example demonstrates a complete last mile delivery scenario for an e-commerce fulfillment center. The solution handles multiple delivery vehicles, customer time windows, package capacities, priority deliveries, and driver shift constraints - all common requirements in modern last mile logistics.
This example combines multiple VRP features including time windows, capacity management, priority handling, and route optimization to create a realistic delivery planning scenario.

Business Scenario

An e-commerce company operates a fulfillment center serving a metropolitan area. They need to:
  • Deliver 50+ packages daily using a fleet of delivery vans
  • Meet customer-selected delivery time windows
  • Prioritize premium customers and same-day deliveries
  • Respect vehicle capacity limits (both weight and volume)
  • Ensure drivers complete routes within their 8-hour shifts
  • Minimize total delivery costs while maintaining service quality

Complete Implementation

{
  "resources": [
    {
      "name": "van-001",
      "shifts": [{
        "from": "2024-03-15T08:00:00",
        "to": "2024-03-15T16:00:00",
        "start": {
          "latitude": 40.7484,
          "longitude": -73.9857
        },
        "end": {
          "latitude": 40.7484,
          "longitude": -73.9857
        },
        "breaks": [{
          "type": "FIXED",
          "from": "2024-03-15T12:00:00",
          "to": "2024-03-15T12:30:00",
          "duration": 1800
        }]
      }],
      "capacity": [150, 2000],  // 150 packages, 2000 kg
      "hourlyCost": 25,
      "category": "CAR",
      "tags": ["refrigerated"]
    },
    {
      "name": "van-002",
      "shifts": [{
        "start": {"latitude": 40.7484, "longitude": -73.9857},
        "end": {"latitude": 40.7484, "longitude": -73.9857},
        "from": "2024-03-15T08:00:00",
        "to": "2024-03-15T16:00:00",
        "breaks": [{
          "type": "FIXED",
          "from": "2024-03-15T12:30:00",
          "to": "2024-03-15T13:00:00",
          "duration": 1800
        }]
      }],
      "capacity": [150, 2000],
      "hourlyCost": 25,
      "category": "CAR"
    },
    {
      "name": "van-003",
      "shifts": [{
        "start": {"latitude": 40.7484, "longitude": -73.9857},
        "end": {"latitude": 40.7484, "longitude": -73.9857},
        "from": "2024-03-15T10:00:00",
        "to": "2024-03-15T18:00:00",
        "breaks": [{
          "type": "WINDOWED",
          "from": "2024-03-15T13:00:00",
          "to": "2024-03-15T15:00:00",
          "duration": 1800
        }]
      }],
      "capacity": [120, 1500],
      "hourlyCost": 25,
      "category": "CAR",
      "tags": ["express"]
    }
  ],
  "jobs": [
    // Premium same-day delivery
    {
      "name": "order-001-premium",
      "location": {
        "latitude": 40.7580,
        "longitude": -73.9855
      },
      "duration": 300,
      "load": [1, 2],  // 1 package, 2 kg
      "priority": 100,
      "windows": [{
        "from": "2024-03-15T09:00:00",
        "to": "2024-03-15T11:00:00",
        "hard": true
      }],
      "tags": [{"name": "premium"}]
    },
    // Standard morning delivery
    {
      "name": "order-002",
      "location": {
        "latitude": 40.7489,
        "longitude": -73.9680
      },
      "duration": 300,
      "load": [2, 5],
      "priority": 50,
      "windows": [{
        "from": "2024-03-15T08:00:00",
        "to": "2024-03-15T12:00:00",
        "hard": true
      }]
    },
    // Afternoon delivery with soft preference
    {
      "name": "order-003",
      "location": {
        "latitude": 40.7614,
        "longitude": -73.9776
      },
      "duration": 300,
      "load": [1, 3],
      "priority": 50,
      "windows": [
        {
          "from": "2024-03-15T14:00:00",
          "to": "2024-03-15T15:00:00",
          "hard": false,
          "weight": 50
        },
        {
          "from": "2024-03-15T13:00:00",
          "to": "2024-03-15T17:00:00",
          "hard": true
        }
      ]
    },
    // Refrigerated item
    {
      "name": "order-004-cold",
      "location": {
        "latitude": 40.7282,
        "longitude": -73.9942
      },
      "duration": 300,
      "load": [3, 8],
      "priority": 75,
      "windows": [{
        "from": "2024-03-15T10:00:00",
        "to": "2024-03-15T14:00:00",
        "hard": true
      }],
      "tags": [{"name": "refrigerated", "hard": true}]
    },
    // Express delivery
    {
      "name": "order-005-express",
      "location": {
        "latitude": 40.7359,
        "longitude": -74.0034
      },
      "duration": 180,
      "load": [1, 1],
      "priority": 90,
      "windows": [{
        "from": "2024-03-15T10:00:00",
        "to": "2024-03-15T12:00:00",
        "hard": true
      }],
      "tags": [{"name": "express", "hard": true}]
    },
    // Bulk delivery
    {
      "name": "order-006-bulk",
      "location": {
        "latitude": 40.7069,
        "longitude": -74.0113
      },
      "duration": 600,
      "load": [10, 50],
      "priority": 30,
      "windows": [{
        "from": "2024-03-15T08:00:00",
        "to": "2024-03-15T17:00:00",
        "hard": true
      }]
    }
    // ... additional orders up to 50+
  ],
  "options": {
    "traffic": 1.2,
    "partialPlanning": false,
    "minimize": "COMPLETION_TIME",
    "routingEngine": "OSM"
  },
  "weights": {
    "travelTimeWeight": 1,
    "workloadWeight": 2,
    "priorityWeight": 5
  }
}

Advanced Features Demonstrated

Multi-Dimensional Capacity

The example uses two-dimensional capacity constraints:
"capacity": [150, 2000],  // [package count, weight in kg]
"load": [1, 2]           // [1 package, 2 kg]
This ensures vehicles don’t exceed either package count or weight limits.

Flexible Time Windows

Combining hard and soft windows provides delivery flexibility:
"windows": [
  {
    "from": "14:00:00",
    "to": "15:00:00",
    "hard": false,     // Preferred window
    "weight": 50       // Penalty if missed
  },
  {
    "from": "13:00:00",
    "to": "17:00:00", 
    "hard": true       // Must deliver within
  }
]

Tag-Based Requirements

Special handling requirements use tag matching:
// Job requirement
"tags": [{"name": "refrigerated", "hard": true}]

// Vehicle capability (resource)
"tags": ["refrigerated"]

Real-World Distance Calculation

Using OSM with traffic multiplier for accurate routing:
"options": {
  "routingEngine": "OSM",
  "traffic": 1.2
}

Best Practices for Last Mile Delivery

1

Define accurate service times

Include realistic durations for parking, walking to door, and customer interaction. Urban deliveries often need 5-10 minutes per stop.
2

Use appropriate time windows

Balance customer preferences with operational efficiency. Offer 2-4 hour windows for residential deliveries.
3

Configure vehicle capacities

Track both volume and weight limits. Consider using 3D capacity for volume if needed.
4

Set priority levels strategically

Use priority 80-100 for same-day/express, 40-60 for standard, and 20-40 for economy deliveries.
5

Enable traffic consideration

Use real-time traffic data during peak hours. Set traffic multiplier between 1.2-1.5 for urban areas.
6

Plan for failed deliveries

Consider using partialPlanning: true and implement re-delivery logic for missed deliveries.

Optimization Strategies

Customer Density Clustering

Group nearby deliveries to minimize travel:
{
  "options": {
    "clusteringDistance": 500,  // meters
    "clusteringTime": 600       // seconds
  }
}

Dynamic Routing

Use the suggest API for same-day additions:
// After initial optimization, add new orders
{
  "jobs": [
    // Existing planned deliveries...
    {
      "name": "urgent-order",
      "priority": 95
      // No initialResource - will be suggested
    }
  ],
  "options": {
    "maxSuggest": 3
  }
}

Cost Optimization

Balance multiple cost factors:
{
  "weights": {
    "travelTimeWeight": 1,    // Minimize driving
    "workloadWeight": 2,      // Balance workload
    "priorityWeight": 5       // Respect priorities
  }
}

Route Timeline Visualization

Performance Metrics

Track these KPIs for last mile delivery:
MetricTargetCalculation
On-time delivery> 95%Deliveries within time window / Total deliveries
Vehicle utilization> 80%Actual capacity used / Total capacity
Cost per delivery<$5Total route cost / Number of deliveries
Average delivery time<8 minTotal service time / Number of stops
First attempt success>90%Successful deliveries / Total attempts

Common Challenges and Solutions

Integration Example

For production systems, integrate with your WMS/OMS for real-time order flow and delivery confirmation.
// Example integration flow
async function optimizeLastMileDeliveries() {
  // 1. Fetch orders from WMS
  const orders = await wms.getOrdersForDelivery();
  
  // 2. Transform to VRP format
  const vrpJobs = orders.map(order => ({
    name: order.id,
    location: order.deliveryAddress.coordinates,
    duration: calculateServiceTime(order),
    load: [order.packageCount, order.totalWeight],
    priority: order.serviceLevel === 'EXPRESS' ? 90 : 50,
    windows: [{
      from: order.deliveryWindow.start,
      to: order.deliveryWindow.end,
      hard: true
    }]
  }));
  
  // 3. Optimize routes
  const solution = await solviceApi.solve({
    resources: fleet,
    jobs: vrpJobs,
    options: deliveryOptions
  });
  
  // 4. Push routes to driver apps
  await publishRoutes(solution);
  
  return solution;
}