skills/last-mile-delivery/SKILL.md
When the user wants to optimize last-mile delivery operations, urban logistics, or final-mile fulfillment. Also use when the user mentions "last mile," "final mile," "urban delivery," "home delivery," "same-day delivery," "delivery density," "delivery windows," or "doorstep delivery." For general route optimization, see route-optimization. For fleet management, see fleet-management.
npx skillsauth add kishorkukreja/awesome-supply-chain last-mile-deliveryInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
You are an expert in last-mile delivery operations and urban logistics. Your goal is to help optimize the final leg of delivery from distribution center to customer, balancing cost efficiency with customer satisfaction in dense urban environments.
Before optimizing last-mile operations, understand:
Service Model
Urban Environment
Current Operations
Operational Constraints
1. Cost Metrics
Typical Benchmarks:
2. Service Metrics
3. Efficiency Metrics
Concept:
Strategies:
import numpy as np
import matplotlib.pyplot as plt
from scipy.spatial import ConvexHull
class DeliveryDensityAnalyzer:
"""
Analyze and optimize delivery density
Higher density = more efficient routes and lower costs
"""
def __init__(self, delivery_locations, orders_per_location):
self.locations = np.array(delivery_locations)
self.orders = np.array(orders_per_location)
def calculate_density_metrics(self):
"""
Calculate delivery density metrics
Returns deliveries per square mile/km
"""
# Calculate convex hull (service area)
if len(self.locations) < 3:
return {'error': 'Need at least 3 locations'}
hull = ConvexHull(self.locations)
service_area = hull.volume # area in 2D
total_deliveries = self.orders.sum()
delivery_density = total_deliveries / service_area if service_area > 0 else 0
return {
'total_deliveries': total_deliveries,
'service_area': service_area,
'delivery_density': delivery_density,
'num_locations': len(self.locations)
}
def identify_high_density_zones(self, radius=2.0):
"""
Identify clusters of high delivery density
These zones justify dedicated resources
"""
from sklearn.cluster import DBSCAN
# Cluster deliveries
clustering = DBSCAN(eps=radius, min_samples=5).fit(self.locations)
labels = clustering.labels_
# Analyze clusters
clusters = []
for cluster_id in set(labels):
if cluster_id == -1: # Noise
continue
cluster_mask = labels == cluster_id
cluster_locations = self.locations[cluster_mask]
cluster_orders = self.orders[cluster_mask]
# Calculate cluster metrics
center = cluster_locations.mean(axis=0)
total_orders = cluster_orders.sum()
radius_from_center = np.max(
np.linalg.norm(cluster_locations - center, axis=1)
)
area = np.pi * radius_from_center ** 2
density = total_orders / area if area > 0 else 0
clusters.append({
'cluster_id': cluster_id,
'center': center,
'num_locations': cluster_mask.sum(),
'total_orders': total_orders,
'radius': radius_from_center,
'density': density
})
return sorted(clusters, key=lambda x: x['density'], reverse=True)
def recommend_density_improvements(self):
"""
Recommend strategies to improve density
"""
metrics = self.calculate_density_metrics()
recommendations = []
# Benchmark density (deliveries per sq mile)
if metrics['delivery_density'] < 20:
recommendations.append({
'priority': 'High',
'strategy': 'Focus marketing on underserved areas',
'rationale': 'Density below 20 deliveries/sq mi is inefficient',
'target': 'Increase to 30+ deliveries/sq mi'
})
if metrics['delivery_density'] < 50:
recommendations.append({
'priority': 'Medium',
'strategy': 'Implement time-based incentives',
'rationale': 'Encourage customers to cluster delivery times',
'target': 'Increase deliveries per route by 20%'
})
# Check for sparse outliers
clusters = self.identify_high_density_zones()
if len(clusters) > 0:
recommendations.append({
'priority': 'High',
'strategy': 'Focus on high-density clusters first',
'rationale': f'Found {len(clusters)} high-density zones',
'target': 'Prioritize service in dense clusters'
})
return recommendations
# Example usage
delivery_locations = np.random.rand(100, 2) * 10 # 100 locations in 10x10 grid
orders_per_location = np.random.poisson(3, 100) # Poisson-distributed orders
analyzer = DeliveryDensityAnalyzer(delivery_locations, orders_per_location)
metrics = analyzer.calculate_density_metrics()
recommendations = analyzer.recommend_density_improvements()
print(f"Delivery density: {metrics['delivery_density']:.1f} deliveries/sq unit")
print(f"Recommendations: {len(recommendations)}")
Density Improvement Tactics:
Problem:
Balanced Approach:
import pandas as pd
from datetime import datetime, timedelta
class TimeWindowOptimizer:
"""
Optimize delivery time windows
Balance customer preference with operational efficiency
"""
def __init__(self, historical_deliveries):
"""
Parameters:
- historical_deliveries: DataFrame with delivery data
columns: ['customer_id', 'requested_window', 'actual_delivery',
'window_width_hours', 'successful']
"""
self.deliveries = historical_deliveries
def analyze_window_preferences(self):
"""
Analyze customer time window preferences
Returns distribution of preferred windows
"""
# Extract hour from requested windows
self.deliveries['preferred_start_hour'] = pd.to_datetime(
self.deliveries['requested_window']
).dt.hour
# Distribution by hour
hourly_demand = self.deliveries.groupby('preferred_start_hour').size()
return {
'hourly_distribution': hourly_demand,
'peak_hour': hourly_demand.idxmax(),
'peak_demand': hourly_demand.max()
}
def calculate_window_efficiency(self):
"""
Calculate efficiency by window width
Wider windows = easier routing, but lower satisfaction
"""
efficiency = self.deliveries.groupby('window_width_hours').agg({
'successful': 'mean', # Success rate
'customer_id': 'count' # Volume
}).rename(columns={'customer_id': 'count', 'successful': 'success_rate'})
return efficiency
def recommend_window_strategy(self):
"""
Recommend optimal window strategy
Balance customer preference with operational needs
"""
window_efficiency = self.calculate_window_efficiency()
recommendations = []
# Default: Offer 2-hour windows during peak times
recommendations.append({
'strategy': '2-hour windows during peak (10 AM - 6 PM)',
'rationale': 'Balance efficiency and satisfaction',
'expected_success_rate': 0.92
})
# Premium: 1-hour windows for higher fee
recommendations.append({
'strategy': '1-hour express windows (+$5 fee)',
'rationale': 'Premium service for time-sensitive customers',
'expected_success_rate': 0.85,
'upcharge': 5.00
})
# Economy: 4-hour or all-day windows for discount
recommendations.append({
'strategy': '4-hour economy windows (-$2 discount)',
'rationale': 'Flexible customers, easier routing',
'expected_success_rate': 0.97,
'discount': -2.00
})
return recommendations
def dynamic_window_pricing(self, date, available_capacity):
"""
Calculate dynamic pricing for time slots
Surge pricing when capacity is constrained
"""
# Predict demand for each time slot
slots = [
'8-10 AM', '10-12 PM', '12-2 PM',
'2-4 PM', '4-6 PM', '6-8 PM'
]
pricing = []
for slot in slots:
# Estimate demand (simplified - use ML in practice)
base_demand = 100
slot_demand = base_demand * np.random.uniform(0.7, 1.3)
# Calculate capacity utilization
utilization = slot_demand / available_capacity
# Dynamic pricing
if utilization < 0.7:
price_modifier = 0.8 # 20% discount
incentive = 'Discount - low demand'
elif utilization < 0.9:
price_modifier = 1.0 # Standard price
incentive = 'Standard pricing'
else:
price_modifier = 1.5 # 50% surge
incentive = 'Surge - high demand'
pricing.append({
'time_slot': slot,
'demand': slot_demand,
'capacity': available_capacity,
'utilization': utilization,
'price_modifier': price_modifier,
'incentive': incentive
})
return pd.DataFrame(pricing)
Time Window Strategies:
Concept:
Dark Store Strategy:
class MicroFulfillmentOptimizer:
"""
Optimize micro-fulfillment center locations
Analyze trade-off between facility costs and delivery savings
"""
def __init__(self, customer_locations, demand, current_hub):
self.customers = np.array(customer_locations)
self.demand = np.array(demand)
self.current_hub = np.array(current_hub)
def calculate_current_distances(self):
"""Calculate distances from current hub to customers"""
distances = np.linalg.norm(
self.customers - self.current_hub,
axis=1
)
return distances
def evaluate_micro_hub_location(self, micro_hub_location):
"""
Evaluate benefit of adding micro-fulfillment center
Returns distance savings and cost impact
"""
current_distances = self.calculate_current_distances()
# Distance to micro hub
distances_to_micro = np.linalg.norm(
self.customers - micro_hub_location,
axis=1
)
# Assign customers to nearest hub
use_micro_hub = distances_to_micro < current_distances
# Calculate savings
distance_savings = (
current_distances[use_micro_hub].sum() -
distances_to_micro[use_micro_hub].sum()
)
customers_served = use_micro_hub.sum()
demand_served = self.demand[use_micro_hub].sum()
return {
'micro_hub_location': micro_hub_location,
'customers_served': customers_served,
'demand_served': demand_served,
'distance_savings': distance_savings,
'avg_distance_reduction': distance_savings / customers_served if customers_served > 0 else 0
}
def optimize_micro_hub_locations(self, num_micro_hubs=3):
"""
Find optimal locations for micro-fulfillment centers
Uses k-means clustering
"""
from sklearn.cluster import KMeans
# Weight locations by demand
weighted_locations = np.repeat(
self.customers,
self.demand.astype(int),
axis=0
)
# Find optimal cluster centers
kmeans = KMeans(n_clusters=num_micro_hubs, random_state=42)
kmeans.fit(weighted_locations)
micro_hub_locations = kmeans.cluster_centers_
# Evaluate each micro hub
results = []
for loc in micro_hub_locations:
result = self.evaluate_micro_hub_location(loc)
results.append(result)
return results
def calculate_micro_hub_roi(self, micro_hub_cost_annual,
demand_served, distance_savings,
cost_per_mile=2.50):
"""
Calculate ROI for micro-fulfillment center
Parameters:
- micro_hub_cost_annual: Annual cost of micro hub
- demand_served: Annual deliveries from micro hub
- distance_savings: Total miles saved per delivery
- cost_per_mile: Delivery cost per mile
"""
# Annual savings from reduced distance
annual_miles_saved = distance_savings * demand_served * 365
annual_cost_savings = annual_miles_saved * cost_per_mile
# Additional savings from faster delivery (premium pricing)
faster_delivery_premium = demand_served * 365 * 2.00 # $2 premium per delivery
total_annual_benefit = annual_cost_savings + faster_delivery_premium
# ROI
net_benefit = total_annual_benefit - micro_hub_cost_annual
roi = net_benefit / micro_hub_cost_annual if micro_hub_cost_annual > 0 else 0
payback_years = micro_hub_cost_annual / total_annual_benefit if total_annual_benefit > 0 else 999
return {
'annual_cost': micro_hub_cost_annual,
'annual_benefit': total_annual_benefit,
'net_benefit': net_benefit,
'roi': roi,
'payback_years': payback_years
}
# Example: Should we open a micro-fulfillment center?
customer_locations = np.random.rand(500, 2) * 20
demand = np.random.poisson(2, 500)
current_hub = np.array([10, 10])
optimizer = MicroFulfillmentOptimizer(customer_locations, demand, current_hub)
micro_hub_results = optimizer.optimize_micro_hub_locations(num_micro_hubs=2)
for idx, result in enumerate(micro_hub_results):
roi = optimizer.calculate_micro_hub_roi(
micro_hub_cost_annual=250000,
demand_served=result['demand_served'],
distance_savings=result['avg_distance_reduction']
)
print(f"\nMicro Hub {idx + 1}:")
print(f" Location: {result['micro_hub_location']}")
print(f" Customers: {result['customers_served']}")
print(f" Annual ROI: {roi['roi']:.1%}")
print(f" Payback: {roi['payback_years']:.1f} years")
Micro-Fulfillment Benefits:
A. Crowdsourced/Gig Delivery
class GigDeliveryOptimizer:
"""
Optimize use of gig delivery drivers
Balance dedicated fleet vs. on-demand gig workers
"""
def __init__(self, base_volume, peak_volume, dedicated_fleet_size):
self.base_volume = base_volume
self.peak_volume = peak_volume
self.dedicated_fleet_size = dedicated_fleet_size
def calculate_cost_comparison(self):
"""
Compare cost of dedicated fleet vs. gig workers
Returns optimal mix
"""
# Dedicated driver costs
driver_annual_cost = 55000 # Salary + benefits
deliveries_per_driver_per_day = 40
dedicated_capacity = self.dedicated_fleet_size * deliveries_per_driver_per_day
# Gig driver costs
gig_cost_per_delivery = 8.50 # Variable cost
# Calculate scenarios
scenarios = []
# Scenario 1: All dedicated
dedicated_only_cost = (
self.dedicated_fleet_size * driver_annual_cost +
max(0, self.peak_volume - dedicated_capacity) * 250 * gig_cost_per_delivery
)
scenarios.append({
'scenario': 'All Dedicated (sized for base)',
'dedicated_drivers': self.dedicated_fleet_size,
'annual_cost': dedicated_only_cost,
'flexibility': 'Low'
})
# Scenario 2: Hybrid (dedicated for base, gig for peak)
base_drivers = int(self.base_volume / deliveries_per_driver_per_day)
peak_overflow = self.peak_volume - (base_drivers * deliveries_per_driver_per_day)
peak_days_per_year = 100 # Assume 100 peak days
hybrid_cost = (
base_drivers * driver_annual_cost +
peak_overflow * peak_days_per_year * gig_cost_per_delivery
)
scenarios.append({
'scenario': 'Hybrid (dedicated base + gig peak)',
'dedicated_drivers': base_drivers,
'annual_cost': hybrid_cost,
'flexibility': 'High'
})
# Scenario 3: Mostly gig
minimal_dedicated = max(1, int(base_drivers * 0.3))
gig_volume = (
self.base_volume * 250 + # Base days
self.peak_volume * 100 # Peak days
) - (minimal_dedicated * deliveries_per_driver_per_day * 350)
mostly_gig_cost = (
minimal_dedicated * driver_annual_cost +
gig_volume * gig_cost_per_delivery
)
scenarios.append({
'scenario': 'Mostly Gig (minimal dedicated)',
'dedicated_drivers': minimal_dedicated,
'annual_cost': mostly_gig_cost,
'flexibility': 'Very High'
})
return sorted(scenarios, key=lambda x: x['annual_cost'])
# Example
optimizer = GigDeliveryOptimizer(
base_volume=1200, # Base daily deliveries
peak_volume=2000, # Peak daily deliveries
dedicated_fleet_size=35
)
scenarios = optimizer.calculate_cost_comparison()
for s in scenarios:
print(f"{s['scenario']}: ${s['annual_cost']:,.0f}")
B. Autonomous Delivery Robots
def evaluate_robot_delivery(delivery_volume, avg_delivery_distance,
robot_cost=5000, robot_capacity=20):
"""
Evaluate feasibility of autonomous delivery robots
For short-distance, high-density urban areas
"""
# Robot economics
robot_deliveries_per_day = 10 # Limited by speed and recharging
robot_lifespan_years = 5
robot_annual_cost = robot_cost / robot_lifespan_years + 500 # Maintenance
# Human delivery cost (benchmark)
human_cost_per_delivery = 7.50
# Robots only viable for short distances
if avg_delivery_distance > 2.0: # miles
return {
'viable': False,
'reason': 'Distance too far for robots',
'recommendation': 'Use traditional delivery'
}
# Calculate breakeven
robots_needed = delivery_volume / robot_deliveries_per_day
robot_total_cost = robots_needed * robot_annual_cost
robot_cost_per_delivery = robot_total_cost / (delivery_volume * 365)
savings = human_cost_per_delivery - robot_cost_per_delivery
annual_savings = savings * delivery_volume * 365
return {
'viable': robot_cost_per_delivery < human_cost_per_delivery,
'robots_needed': int(np.ceil(robots_needed)),
'robot_cost_per_delivery': robot_cost_per_delivery,
'human_cost_per_delivery': human_cost_per_delivery,
'annual_savings': annual_savings,
'payback_years': (robots_needed * robot_cost) / annual_savings if annual_savings > 0 else 999
}
C. Locker & Pickup Points
class LockerNetworkOptimizer:
"""
Optimize parcel locker network
Reduce failed deliveries and cost for flexible customers
"""
def __init__(self, customer_locations, customer_flexibility):
"""
Parameters:
- customer_locations: (x, y) coordinates
- customer_flexibility: 0-1, willingness to use locker
"""
self.customers = np.array(customer_locations)
self.flexibility = np.array(customer_flexibility)
def optimize_locker_locations(self, num_lockers=10,
max_distance=1.0):
"""
Find optimal locker locations
Parameters:
- num_lockers: Number of lockers to place
- max_distance: Max distance customers will travel (miles)
"""
from sklearn.cluster import KMeans
# Weight by flexibility (prioritize flexible customers)
weighted_customers = self.customers[self.flexibility > 0.5]
if len(weighted_customers) < num_lockers:
return {'error': 'Not enough flexible customers'}
# Cluster to find locker locations
kmeans = KMeans(n_clusters=num_lockers, random_state=42)
kmeans.fit(weighted_customers)
locker_locations = kmeans.cluster_centers_
# Analyze coverage
coverage = []
for locker_loc in locker_locations:
distances = np.linalg.norm(
self.customers - locker_loc,
axis=1
)
# Customers within max distance and flexible
within_range = distances <= max_distance
flexible_enough = self.flexibility > 0.5
covered = within_range & flexible_enough
coverage.append({
'location': locker_loc,
'customers_covered': covered.sum(),
'deliveries_diverted': covered.sum() # Assume 1 delivery per customer
})
return coverage
def calculate_locker_roi(self, locker_cost_annual,
deliveries_diverted,
home_delivery_cost=8.50,
locker_delivery_cost=2.50):
"""
Calculate ROI for locker network
Lockers consolidate deliveries, reducing cost
"""
# Cost savings per delivery
savings_per_delivery = home_delivery_cost - locker_delivery_cost
# Annual savings
annual_savings = deliveries_diverted * 365 * savings_per_delivery
# ROI
net_benefit = annual_savings - locker_cost_annual
roi = net_benefit / locker_cost_annual if locker_cost_annual > 0 else 0
return {
'annual_cost': locker_cost_annual,
'annual_savings': annual_savings,
'net_benefit': net_benefit,
'roi': roi
}
Route Optimization:
Delivery Management:
Customer Experience:
# Example: Integration with route optimization API
import requests
import json
def optimize_routes_api(stops, depot, api_key):
"""
Call route optimization API
Example using generic API structure
"""
url = "https://api.routeoptimizer.com/v1/optimize"
payload = {
"depot": {
"lat": depot['lat'],
"lon": depot['lon']
},
"stops": [
{
"id": stop['id'],
"lat": stop['lat'],
"lon": stop['lon'],
"demand": stop['demand'],
"time_window": stop['time_window'],
"service_time": stop['service_time']
}
for stop in stops
],
"vehicles": {
"count": 5,
"capacity": 100,
"start_time": "08:00",
"end_time": "18:00"
}
}
headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
if response.status_code == 200:
result = response.json()
return result['routes']
else:
return {'error': response.text}
Problem:
Solutions:
Problem:
Solutions:
Problem:
Solutions:
Problem:
Solutions:
Problem:
Solutions:
Executive Summary:
Current Performance:
| Metric | Current | Industry Benchmark | Gap | |--------|---------|-------------------|-----| | Cost per delivery | $9.20 | $7.50 | ⚠️ 23% higher | | Stops per hour | 6.2 | 8.0 | ⚠️ 23% lower | | First-attempt success | 88% | 92% | ⚠️ 4% lower | | Delivery density | 22/sq mi | 35/sq mi | ⚠️ 37% lower | | Route efficiency | 78% | 85% | ⚠️ 7% lower |
Cost Breakdown:
| Component | Cost per Delivery | % of Total | |-----------|------------------|------------| | Driver labor | $4.20 | 46% | | Vehicle (fuel, maintenance) | $2.50 | 27% | | Hub/overhead | $1.80 | 20% | | Failed deliveries | $0.70 | 8% | | Total | $9.20 | 100% |
Optimization Opportunities:
Improve delivery density (+15%)
Reduce failed deliveries (12% → 6%)
Optimize time windows
Route optimization software
Implementation Plan:
| Initiative | Timeline | Investment | Annual Savings | Payback | |----------|----------|------------|----------------|---------| | Route optimization software | Q1 | $50K | $420K | 1.4 months | | Parcel locker network | Q2-Q3 | $180K | $225K | 9.6 months | | 2 micro-fulfillment hubs | Q4 | $500K | $650K | 9.2 months | | Customer notification system | Q1 | $25K | $150K | 2.0 months |
Expected Results (Year 1):
| Metric | Current | Year 1 Target | Improvement | |--------|---------|---------------|-------------| | Cost per delivery | $9.20 | $7.50 | -18% | | Stops per hour | 6.2 | 8.0 | +29% | | Failed deliveries | 12% | 6% | -50% | | On-time delivery | 91% | 96% | +5 pts | | Customer satisfaction | 4.1/5 | 4.5/5 | +0.4 |
If you need more context:
documentation
When the user wants to optimize yard operations, manage trailer parking, or improve dock door utilization. Also use when the user mentions "yard management," "trailer tracking," "yard jockey," "drop trailer program," "trailer pool," "dock scheduling," or "gate management." For cross-dock operations, see cross-docking. For warehouse design, see warehouse-design.
tools
When the user wants to optimize workforce scheduling, create shift plans, or balance labor demand. Also use when the user mentions "staff scheduling," "labor planning," "shift optimization," "crew scheduling," "roster optimization," or "employee scheduling." For task assignment, see task-assignment-problem. For wave planning labor, see wave-planning-optimization.
testing
When the user wants to optimize pick wave planning, schedule warehouse operations, or improve order fulfillment efficiency. Also use when the user mentions "wave management," "batch picking," "pick wave scheduling," "order release optimization," "wave design," or "pick wave strategy." For order batching, see order-batching-optimization. For workforce scheduling, see workforce-scheduling.
testing
When the user wants to optimize warehouse slot assignments, improve pick efficiency, or design warehouse layouts. Also use when the user mentions "slotting optimization," "slot assignment," "ABC slotting," "pick path optimization," "storage location assignment," "warehouse layout optimization," or "forward pick locations." For picker routing, see picker-routing-optimization. For warehouse design, see warehouse-design.