> ## Documentation Index
> Fetch the complete documentation index at: https://reportana.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Delivery Time

In this example, we use the **Execute JavaScript** block to calculate the delivery time based on the customer's region.

1. First, within the automation structure, we ask the customer to send the abbreviation corresponding to the state they live in. *For example: Send "SP" for those who live in São Paulo*.

<img src="https://mintcdn.com/reportana/cEIYEKOrJ1QXoaCs/DeliveryTime1-en.png?fit=max&auto=format&n=cEIYEKOrJ1QXoaCs&q=85&s=0220c3d47dfa2e5f0c7e9447a437b67a" alt="Example of Delivery Time: image 1" width="1732" height="838" data-path="DeliveryTime1-en.png" />

2. Next, we save the customer's response in the variable `payload.state`.

<img src="https://mintcdn.com/reportana/cEIYEKOrJ1QXoaCs/DeliveryTime2-en.png?fit=max&auto=format&n=cEIYEKOrJ1QXoaCs&q=85&s=47e850dfb1ec5ebe40a8ce36a48af414" alt="Example of Delivery Time: image 2" width="1298" height="509" data-path="DeliveryTime2-en.png" />

3. In **Execute JavaScript**, we use the variable `payload.state` to run the code that checks the delivery time based on the region provided by the client.

<img src="https://mintcdn.com/reportana/cEIYEKOrJ1QXoaCs/DeliveryTime3-en.png?fit=max&auto=format&n=cEIYEKOrJ1QXoaCs&q=85&s=3db0c3d93e47b646ef7f9b6256fbd0b8" alt="Example of Delivery Time: image 3" width="787" height="442" data-path="DeliveryTime3-en.png" />

4. Finally, the result of the code will be saved in the variable `payload.deadline`, which is sent to the client in the last message indicating the delivery time according to the informed region.

**Note:** In the example, we also implement error handling in the code, so if the abbreviation provided by the client does not correspond to any Brazilian state, an error message will be displayed requesting them to try again.

<RequestExample>
  ```javaScript Example Code theme={null}
  // Capture the state provided by the client
  var state = payload.state.toUpperCase(); // Convert to uppercase for standardization

  // Calculate delivery time based on the US state
  if (['NY', 'NJ', 'CT', 'PA'].includes(state)) {
    payload.deadline = 'Delivery within up to 3 business days'; // Northeast Region
  } else if (['CA', 'OR', 'WA', 'NV'].includes(state)) {
    payload.deadline = 'Delivery within up to 4 business days'; // West Coast
  } else if (['TX', 'OK', 'LA', 'AR'].includes(state)) {
    payload.deadline = 'Delivery within up to 5 business days'; // South Central
  } else if (['IL', 'IN', 'OH', 'MI'].includes(state)) {
    payload.deadline = 'Delivery within up to 4 business days'; // Midwest
  } else if (['FL', 'GA', 'SC', 'NC'].includes(state)) {
    payload.deadline = 'Delivery within up to 5 business days'; // Southeast
  } else {
    payload.deadline = 'State not recognized. Please check the abbreviation and try again.'; // Error handling
  }
  ```
</RequestExample>
