quotes

This endpoint will poll Karhoo’s quote engine continuously and return a list of quotes related to the QuoteSearch provided. Quotes will expire after 300 seconds. The SDK handles this for you and will refresh the quote search before the expiry time.

quotes(quotesSearch: QuotesSearch) : PollCall<Quotes>

The QuoteSearch model takes an optional ‘scheduledDate’. If scheduledDate is nil, the QuoteService will look for ASAP quotes. These quotes will contain a quoted time of arrival (QTA) estimate and are for users that require a vehicle as soon as possible. Providing a scheduledDate will return prebook quotes for that date.

Parameters

  • quoteSearch: QuoteSearch

Returns

  • PollCall<Quotes>

Errors

K3001 Could not get estimates
K3002 Could not get estimates (no availability found within requested area)
K3003 Could not get estimates (could not find specified quote)

Examples

iOS

let quoteService = Karhoo.getQuotesService()

// create request
let quoteSearch = QuoteSearch(origin: originLocationDetails,
                              destination: destinationLocationDetails, 
                              dateScheduled: scheduledDate)

// create observer
let quoteSearchObserver = Observer<Quotes> { [weak self] result in
    switch result {
        case .success(let quotes):
            print("Quotes: \(quotes.all)")
        case .failure(let error):
            // handle error (KarhooError)
    }
}

// create observable
let quotesObservable = quotesService.quotes(quoteSearch: quoteSearch).observable()

// subscribe observer to observable
quotesObservable.subscribe(observer: quoteSearchObserver)

// unsubscribe observer from observable when finished
quotesObservable.unsubscribe(observer: quoteSearchObserver)

Android

// Create observer 
val observer = object : Observer<Resource<QuoteList>> {
    override fun onValueChanged(value: Resource<QuoteList>) {
        when (value) {
            is Resource.Success -> updateVehicles(value.data)
            is Resource.Failure -> handleAvailabilityError(value.error)
        }
    }
}

// Create request
val quotesSearch = QuotesSearch(origin: LocationInfo,
                destination: LocationInfo,
                date: Date?)

// Poll for quotes
val quotesObservable = quotesService
   .quotes(quotesSearch)
   .observable()
   .apply { subscribe(observer) }

//unsubscribe when done
quotesObservable.unsubscribe(observer)