I’m working on a scenario where I need to perform a lot of calculations. I’ve started storing the shipping rules in a Datastore, but I’m finding it challenging to find the most efficient method for the calculations. Could you offer some guidance?
FYI, I’ve written a Python script that does what is needed, and it works without any issues: Google Colab.
Below is an example input:
{
"product_code": "iphone-15-pro-blue-1",
"order_quantity": 34,
"shipping_country": "US",
"US_units": 12,
"DE_units": 10,
"FR_units": 10,
"UK_units": 0
}
For the provided input, the output JSON should be:
{
"1 business day": "12 units",
"5 business days": "20 units",
"Supplier backordered; delivery time to be confirmed": "2 units"
}
The shipping times in days table from each location:
shipping_rules = {
"US": {"US": 1, "DE": 5, "FR": 5, "UK": 5},
"FR": {"US": 5, "DE": 3, "FR": 1, "UK": 3},
"DE": {"US": 5, "DE": 1, "FR": 3, "UK": 3},
"UK": {"US": 5, "DE": 3, "FR": 3, "UK": 1}
}
Prioritize shipping locations with available stock until the stock is 0. Then, prioritize by shorter delivery times.