# 10 - Better Selection of Shipment Prices

**Status: NOT STARTED**

## Summary

Reinstate multi-carrier rate comparison that automatically selects the cheapest shipping option across all available carriers (UPS, DHL, USPS, Sendle).

## Current State

The infrastructure exists but may not be working correctly:
- `createShipmentRateEstimate` in `ShippingAdminApi.ts` queries Shippo for rates from multiple carriers
- Rates are returned sorted by price (lowest first)
- The UI in `BigShipment.jsx` can display and select from available rates
- Carrier accounts configured: UPS, DHL, USPS, Sendle

However, the automatic selection of cheapest rate may not be working, or the rate display/selection flow may be disabled.

## Requirements

1. Verify and fix `createShipmentRateEstimate` to return all carrier rates
2. Enable auto-selection of cheapest rate in `generateShippingLabelInternal`
3. Ensure rate comparison UI is visible and functional in single-shipment view
4. Add cheapest-rate option to batch processing

## Files to Modify

| File | Change |
|------|--------|
| `api/src/fabricator/ShippingAdminApi.ts` | Review/fix `createShipmentRateEstimate` (lines 3695-3830) to return all carrier rates |
| `api/src/fabricator/ShippingAdminApi.ts` | Add or enable auto-selection of cheapest rate in `generateShippingLabelInternal` |
| `webapps/src/components/BigLogistics/BigShipment.jsx` | Ensure rate comparison UI is visible and functional |
| `webapps/src/components/BigLogistics/BigBatchShipper.jsx` | Add option to use cheapest rate in batch processing |

## Key Code Locations

- Rate calculation: `ShippingAdminApi.ts` lines 3695-3830 (`createShipmentRateEstimate`)
- Carrier account IDs:
    - UPS Main: `5162778754904d31a0a61c919ba0b66a`
    - UPS EU: `278f870edc4d4e66b4abe90361282607`
    - DHL Export: `bd29c54a1c3049aaa9b3b28d1661ab38`
    - DHL Import: `1b92670b789846ff9f1dc712b7e54d30`

## Expected Behavior

The `CalculateShippingRates` action should:
1. Query all active carrier accounts
2. Filter out incompatible service levels
3. Sort by price
4. Return full list for manual selection OR auto-select cheapest

## Implementation Notes

- This is primarily a debugging/restoration task -- the infrastructure exists
- Need to investigate why the feature isn't working before implementing fixes
- Batch shipper integration is the highest-value addition
