Integration of Delivery Cost Calculation via API

Integration of Delivery Cost Calculation via API

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:

Frequently Asked Questions

Latest works

  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1281
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1237
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    977
  • image_crm_chasseurs_493_0.webp
    CRM development for Chasseurs
    1026
  • image_website-sbh_0.webp
    Website development for SBH Partners
    1103
  • image_website-_0.webp
    Website development for Red Pear
    550

Integration of Delivery Cost Calculation via API

A customer adds a product to the cart, proceeds to checkout — and the delivery cost turns out unexpectedly high. They abandon the cart. Sound familiar? We solve this by automatically calculating delivery cost via API, showing real rates at the selection stage. Our experience: years of expertise and 15+ successful integrations for e-commerce stores of all sizes.

Imagine: the customer has already chosen a product, filled in the details, but at the delivery selection step they see a message "calculate delivery separately." That makes them leave. Our solution shows accurate cost and delivery time from multiple providers right in the cart, in real time. We integrate APIs of CDEK, Boxberry, Russian Post, and other services, unify their responses, and cache results for fast loading. With parallel asynchronous requests, the user waits no more than 2–3 seconds. This reduces cart abandonment by 20–30%.

Problems We Solve

Implementing delivery calculation via API is not just "calling a provider endpoint." Here are typical challenges:

  • N+1 queries: if you poll each provider sequentially, waiting time can exceed 10 seconds. We use parallel asynchronous requests, reducing delay to the response time of the slowest provider.
  • Timeouts and errors: APIs may be unavailable. We set a 2-second timeout per request. If a provider is silent, its option is simply not shown.
  • Non-unified formats: each service has its own response structure. We convert them to a single DeliveryOption object, convenient for both backend and frontend.
  • Caching: repeating the same request should not hammer external APIs. We cache the result for 15 minutes, speeding up returning to the checkout page.

How Parallel API Polling Works

At the core is a DeliveryCalculator component that gets a list of providers and runs calculations in parallel. For async work we use Guzzle Pool or ReactPHP. Here's an example implementation:

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()); } } 

Each provider returns a DeliveryOption object with a unified structure:

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 cents public ?int $priceWithDiscount; public int $minDays; public int $maxDays; public ?string $pvzCode; // if a pickup point needs to be selected public array $meta; // additional provider data } 

Why Caching Calculation Results Matters

Caching reduces load on provider APIs and speeds up repeat requests. We use a key {cart_hash}:{destination_hash} with a TTL of 10–15 minutes. When the cart contents or address change, the cache is invalidated:

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

What the Work Includes

Stage Content Time (work days)
Audit Analysis of current cart and available providers 0.5
API connection Integration of 2–3 providers (CDEK, Boxberry, Russian Post) 2–3
Parallel requests Implementing async polling, timeouts, error handling 1–2
Caching Setting up cache and invalidation on cart events 0.5
UI Displaying options with pickup point selection on a map, delivery time 1–2
Testing Verification with real orders, performance testing 1

Total: from 3 business days for basic integration.

Comparison of Approaches

Criterion Manual entry API calculation (our solution)
Rate accuracy Low (outdated) High (real-time)
Number of providers No more than 1–2 5 or more
Dimension handling No Automatic (from product card)
Errors High probability Minimized (timeouts, caching)
Conversion Low 20–30% higher

Typical Integration Mistakes

  • Not handling product dimensions. If dimensions are missing, we use defaults — otherwise the provider may reject or overcharge.
  • Ignoring the production calendar. A delivery time of "1–2 days" without accounting for holidays misleads the customer. We tie to business days.
  • Not testing with real carts. Often an error appears only with a large number of items or non-standard addresses.

According to CDEK documentation, the request timeout should not exceed 5 seconds.

What You Get After Integration

  • Working cost calculation for 2–3 providers
  • Parallel requests with timeouts
  • Caching with automatic invalidation
  • Display of options on the site with pickup point selection and delivery times
  • Code and access documentation
  • 30-day warranty on integration after delivery

Contact us to assess your project. We'll provide a detailed estimate of timeline and cost, and advise on provider selection. Request a consultation on delivery calculation integration — we'll help find the optimal solution.