Determine Shipping Lead Time

This is more of a logical / can-this-be-built type of question.

I’m building a shipping tool to estimate a shipping date based on a predefined arrival date and zip code. This means using only the arrival date and zip code I need to somehow calculate the best-possible shipping date so that it will arrive on the date as scheduled.

I have a working API connection to my shipping carrier’s time-in-transit API.

The API accepts:
(1) Shipping date
(2) Ship From zip code
(3) Ship To zip code

The API returns:
(1) arrival date

Any thoughts of how I can use this to figure out?

Thanks in advance! I’ve included some additional info below as well.

My current idea (not fully formed)
I’m considering a trial-and-error approach querying one day before the arrival date and checking the response matches the arrival date, then 2 days and checking again, 3 days, etc. I’m not really sure how I would set that up though? Bubble doesn’t really have any ability to loop? Not sure how I would do this in a sensible manner with API workflows.

How this tool will be used

  • I have a list of customer orders (with arrival dates and zips) in the Db I would need to work on and then update with their calculated ‘ship date’
  • Existing orders in the db need to be kept up-to-date and new orders need to be estimated as they come in.
  • This needs to be a pre-scheduled workflow that repeats on a daily, weekly, etc basis (API workflow)

More About Shipping

  • Shipping time-in-transit takes between 1-8 days (UPS Ground) depending on ZIP
  • I cannot use faster / more time-consistent shipping method (Too expensive)
  • This really does need to be as accurate as possible and should use the API. You can do an OK job estimating time in transit without an API by using a lookup for various shipping ‘zones’ (I’m doing this with a spreadsheet now), but its not really good enough.

Brainstorming a bit here, but it looks like I could schedule a recurring event (Workflow A ‘The scheduler’) that triggers an API endpoint (Workflow B ‘the order updater’) on a list of orders. Workflow B could then turn around and trigger another API endpoint (Workflow C ‘the api fetcher’) on a list of dates

Does this seem like the right approach?

Workflow A - Schedule (Finds a list of orders)

Workflow B - Order 1

Workflow C - Order 1 / Date Trial #1
Workflow C - Order 1 / Date Trial #2
Workflow C - Order 1 / Date Trial #3
Workflow C - Order 1 / Date Trial #4
Workflow C - Order 1 / Date Trial #5
Workflow C - Order 1 / Date Trial #6
Workflow C - Order 1 / Date Trial #7
Workflow C - Order 1 / Date Trial #8

Workflow A - Schedule (Finds a list of orders)

Workflow B - Order 2
Workflow C - Order 2 / Date Trial #1
Workflow C - Order 2 / Date Trial #2
Workflow C - Order 2 / Date Trial #3
Workflow C - Order 2 / Date Trial #4
Workflow C - Order 2 / Date Trial #5
Workflow C - Order 2 / Date Trial #6
Workflow C - Order 2 / Date Trial #7
Workflow C - Order 2 / Date Trial #8

Workflow A - Schedule (Finds a list of orders)

Workflow B - Order 3

Workflow C - Order 3 / Date Trial #1
Workflow C - Order 3 / Date Trial #2
Workflow C - Order 3 / Date Trial #3
Workflow C - Order 3 / Date Trial #4
Workflow C - Order 3 / Date Trial #5
Workflow C - Order 3 / Date Trial #6
Workflow C - Order 3 / Date Trial #7
Workflow C - Order 3 / Date Trial #8

Hey @jon2,

You actually can do a pseudo loop by using an API endpoint that schedules itself.

Perhaps you can setup an endpoint that takes a “date_to_test” date value as a parameter. You call the endpoint to get it started passing it the first date to evaluate, check the api using that date, and then if you don’t get the result you want, use an action to (re)schedule the same endpoint, but this time pass it the next date in your sequence using the date operation to add/subtract 1 day

Maybe that will get you a step closer?



Looking to improve your Bubble™ skills?

Let me turn
:thinking: :tired_face: :confounded:

into
:grinning: :sunglasses: :woman_student:

Coaching and Development at https://uniqueideas.com or schedule a free intro session :gift:

Ken Truesdale
LinkedIn

Thanks @mebeingken!

I was thinking about just this! I’m wondering what might happen if I don’t get an exact match in this function?

For example: the arrival date might be near or on a holiday. Let’s say the ideal day for the package to arrive is July 4th, but UPS doesn’t deliver on that day. The API wouldn’t return 07/04 as a result. It may return 7/3 and 7/5, however. I don’t want to have loop too long and I’d like to be able to define which side of the delivery date I’ll settle on…

I’m also wondering if there is a (reasonable) way to optimize the number of calls to the API I’m making. I was thinking of calculating the difference between the returned date from the API and my ideal delivery date then passing that difference to the next API to better ‘guess’ the next ship date. But I’m wondering how I can build-in a persistent over-arching logic in this ‘psuedo loop’ API workflow that will properly ‘zero in’ on the ideal date each time it is fed input data.