DEV Community

Thesius Code
Thesius Code

Posted on • Originally published at datanest-stores.pages.dev

Order Fulfillment Pipeline

Order Fulfillment Pipeline

End-to-end order processing automation covering validation, shipping label generation, carrier tracking, customer notifications, and returns management. Move orders from placed to delivered with minimal manual intervention.

Key Features

  • Order Validation — Address verification, fraud scoring, inventory hold
  • Shipping Label Generation — Multi-carrier label creation with rate shopping
  • Tracking Integration — Automatic tracking number assignment and status polling
  • Customer Notifications — Email/SMS at each fulfillment stage
  • Returns Processing — RMA generation, return label creation, refund triggers
  • Priority Routing — Route orders to nearest warehouse based on destination

Quick Start

# 1. Extract and configure
unzip order-fulfillment-pipeline.zip
cd order-fulfillment-pipeline
cp config.example.yaml config.yaml

# 2. Process pending orders
python -m order_fulfillment.core --process-pending --config config.yaml

# 3. Check fulfillment status
python -m order_fulfillment.core --status --order-id ORD-20260323-001
Enter fullscreen mode Exit fullscreen mode

Architecture

src/order_fulfillment/
├── core.py              # Pipeline orchestrator: validate → route → ship → notify
├── validation.py        # Address verification, fraud checks, stock holds
├── shipping.py          # Carrier APIs, label generation, rate comparison
├── tracking.py          # Tracking status polling and event processing
├── notifications.py     # Email/SMS templates and dispatch
└── returns.py           # RMA workflow, return labels, refund processing
Enter fullscreen mode Exit fullscreen mode

Pipeline Stages: Order Placed → Validated → Routed → Label Created → Shipped → Delivered

Usage Examples

Process a New Order

from order_fulfillment.core import FulfillmentPipeline

pipeline = FulfillmentPipeline(config_path="config.yaml")

order = {
    "order_id": "ORD-20260323-001",
    "customer_email": "customer@example.com",
    "items": [
        {"sku": "WIDGET-BLU-LG", "quantity": 2, "price": 29.99},
        {"sku": "GADGET-RED-SM", "quantity": 1, "price": 49.99},
    ],
    "shipping_address": {
        "name": "Jane Smith",
        "street": "123 Main St",
        "city": "Portland",
        "state": "OR",
        "zip": "97201",
        "country": "US"
    }
}

result = pipeline.process(order)
print(f"Status: {result['status']}")            # Status: label_created
print(f"Carrier: {result['carrier']}")           # Carrier: ups
print(f"Tracking: {result['tracking_number']}")  # Tracking: 1Z999AA10123456784
Enter fullscreen mode Exit fullscreen mode

Rate Shopping

from order_fulfillment.shipping import RateShopper

shopper = RateShopper(config_path="config.yaml")
rates = shopper.get_rates(
    weight_oz=32,
    dimensions={"length": 12, "width": 8, "height": 6},
    destination_zip="97201"
)

for rate in rates:
    print(f"{rate['carrier']} {rate['service']}: ${rate['price']:.2f} "
          f"({rate['estimated_days']} days)")
Enter fullscreen mode Exit fullscreen mode

Order Status Query

-- Fulfillment pipeline status report
SELECT
    o.order_id,
    o.order_date,
    o.current_stage,
    s.carrier,
    s.tracking_number,
    s.label_created_at,
    s.shipped_at,
    s.delivered_at,
    DATEDIFF(DAY, o.order_date, COALESCE(s.delivered_at, CURRENT_DATE)) AS days_in_pipeline
FROM orders o
LEFT JOIN shipments s ON o.order_id = s.order_id
WHERE o.order_date >= CURRENT_DATE - INTERVAL '7 days'
ORDER BY o.current_stage, o.order_date;
Enter fullscreen mode Exit fullscreen mode

Process a Return

from order_fulfillment.returns import ReturnManager

returns_mgr = ReturnManager(config_path="config.yaml")
rma = returns_mgr.create_rma(
    order_id="ORD-20260323-001",
    items=[{"sku": "WIDGET-BLU-LG", "quantity": 1, "reason": "defective"}],
    refund_method="original_payment"
)
print(f"RMA #{rma['rma_id']} — return label: {rma['return_tracking']}")
Enter fullscreen mode Exit fullscreen mode

Configuration

carriers:
  ups:
    enabled: true
    api_key: "YOUR_UPS_API_KEY"
    account_number: "YOUR_UPS_ACCOUNT"
    default_service: "ground"
  usps:
    enabled: true
    api_key: "YOUR_USPS_API_KEY"

fulfillment:
  auto_process: true              # Auto-process orders as they arrive
  rate_shop: true                 # Compare carrier rates before label creation
  preferred_carrier: "cheapest"   # cheapest | fastest | <carrier_name>
  hold_for_fraud_score: 0.7       # Hold orders above this fraud score

notifications:
  enabled: true
  stages: ["shipped", "delivered", "return_received"]
  email_from: "orders@example.com"

returns:
  rma_expiry_days: 30
  auto_refund: false              # Require manual approval for refunds
  return_shipping: "prepaid"      # prepaid | customer_pays
Enter fullscreen mode Exit fullscreen mode

Best Practices

  1. Validate addresses before labeling — Bad addresses cause carrier rejections and fees
  2. Rate shop for non-urgent orders — Savings of 15-30% on average
  3. Set fraud thresholds conservatively — Start at 0.8, lower gradually
  4. Automate tracking updates — Poll carrier APIs every 2 hours
  5. Keep return windows clear — Communicate RMA expiry dates in emails

Troubleshooting

Issue Cause Fix
Label creation fails Invalid address Run address validation before shipping step
Orders stuck in "validated" No carrier API key configured Check carrier credentials in config
Tracking not updating Carrier API rate limit hit Increase polling interval
Return label not generating RMA expired Check rma_expiry_days setting

This is 1 of 11 resources in the Retail Automation Pro toolkit. Get the complete [Order Fulfillment Pipeline] with all files, templates, and documentation for $39.

Get the Full Kit →

Or grab the entire Retail Automation Pro bundle (11 products) for $139 — save 30%.

Get the Complete Bundle →


Related Articles

Top comments (0)