stage 2 of 6 · try of as-shipped

quote-options

right

Every Tern service for a cart, cheapest first (needs from the docs: D1 grams, D2 current endpoint)

Made
28 Nov 2026, 20:39 UTC
Model
claude-sonnet-5-5
Steps
5
Tool calls
3
Friction
1 flagged step
Tokens read
101k
Time
10s
Cost
$0.032
Address
tern-docs/try/20261128-2029-7znr/quote-options
1quote-at-checkoutright2quote-optionsright3book-shipmentright4sync-shipmentsright5order-statusright6cancel-before-pickupright
diff --git a/shop/shipping.py b/shop/shipping.py
index 5c4358a..7ff2fa2 100644
--- a/shop/shipping.py
+++ b/shop/shipping.py
@@ -1,6 +1,7 @@
 """Shipping with Tern, our carrier. Use shop.tern.call for requests; shop.settings has the warehouse postcode."""
 from datetime import date
 
+from shop import settings, tern
 from shop.cart import Cart
 from shop.orders import Order
 
@@ -13,7 +14,16 @@ def quote_at_checkout(cart: Cart, postcode: str) -> int:
 def quote_options(cart: Cart, postcode: str) -> list[tuple[str, int, int]]:
     """Every service Tern offers for this cart and postcode, as (service, price in pence, days to deliver),
     cheapest first."""
-    raise NotImplementedError
+    grams = round(cart.total_weight_kg() * 1000)
+    status, body = tern.call("POST", "/v2/quotes", {
+        "from_postcode": settings.WAREHOUSE_POSTCODE,
+        "to_postcode": postcode,
+        "weight": grams,
+    })
+    if status != 200:
+        raise RuntimeError(f"Tern quote failed ({status}): {body}")
+    options = [(q["service"], q["amount"], q["eta_days"]) for q in body["quotes"]]
+    return sorted(options, key=lambda o: (o[1], o[2]))
 
 
 def book(order: Order, service: str) -> str: