Delivery Cost Calculation via API Integration

Our company is engaged in the development, support and maintenance of sites of any complexity. From simple one-page sites to large-scale cluster systems built on micro services. Experience of developers is confirmed by certificates from vendors.
Development and maintenance of all types of websites:
Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Our competencies:
Development stages
Latest works
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1161
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1041
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    822
  • image_crm_chasseurs_493_0.webp
    CRM development for Chasseurs
    847
  • image_website-sbh_0.png
    Website development for SBH Partners
    999
  • image_website-_0.png
    Website development for Red Pear
    451

Delivery Cost Calculation API Integration

Real-time delivery cost calculation is a critical conversion element. The customer must see the exact cost of each delivery option during selection, not after confirming the order. This reduces abandonment at the final checkout step.

Calculation Architecture

Cost calculation is performed with a single request to the backend, which simultaneously queries the APIs of all connected delivery services and returns a unified list of options.

class DeliveryCalculator
{
    private array $providers;

    public function calculate(Cart $cart, Address $destination): Collection
    {
        $requests = collect($this->providers)->map(function ($provider) use ($cart, $destination) {
            return $provider->calculateAsync($cart, $destination); // returns Promise
        });

        return collect(async_all($requests))  // parallel execution
            ->flatten()
            ->sortBy('price')
            ->filter(fn($option) => $option->isAvailable());
    }
}

Parallel requests via Guzzle Pool or ReactPHP HTTP. Timeout for each external request is no more than 2–3 seconds. If a provider doesn't respond, their option is simply excluded from the list.

Unified Delivery Option Format

class DeliveryOption
{
    public string $providerId;    // 'cdek', 'boxberry', 'pochta'
    public string $serviceCode;   // 'cdek_express', 'cdek_pvz'
    public string $name;          // 'CDEK: Express'
    public string $type;          // 'courier' | 'pvz' | 'postamat'
    public int $price;            // in kopecks
    public ?int $priceWithDiscount;
    public int $minDays;
    public int $maxDays;
    public ?string $pvzCode;      // if pickup point selection is needed
    public array $meta;           // additional provider data
}

Result Caching

Calculation repeats whenever the address or cart contents change. Caching makes sense with the key {cart_hash}:{destination_hash} for 10–15 minutes.

$cacheKey = "delivery:{$cart->hash()}:{$destination->hash()}";
return Cache::remember($cacheKey, 900, fn() => $this->fetchFromProviders($cart, $destination));

Calculation Parameters

Each provider requires different parameters, but the basics are common:

  • Package dimensions and weight (total across all items in the cart)
  • Origin city/region (warehouse address)
  • Destination city/region
  • Declared value (affects insurance cost)
  • Number of pieces

Dimensions are extracted from products: if the seller hasn't provided them, default values are applied.

Multiple Warehouses and Dispatch Points

E-commerce stores with multiple warehouses should calculate delivery from the closest warehouse to the customer's address. This requires preliminary routing logic: determine which warehouse will ship each item and calculate delivery from each warehouse separately.

Displaying Results

On the UI, results are grouped as follows:

  • Courier delivery: multiple options by speed/cost
  • Pickup from PVZ: click → opens pickup point selection map
  • Russian Post: separately (usually slower, cheaper)

Delivery speed is displayed as "1–2 business days" or "by March 15" — this requires a production calendar (holidays, weekends).

Integration timeframe: 3–5 days to connect 2–3 providers with parallel requests and caching.