Class: Odfl

Inherits:
Object
  • Object
show all
Defined in:
lib/odfl.rb,
lib/odfl/version.rb

Constant Summary collapse

VERSION =
"1.1.2"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(log = false, log_level = :debug, pretty_print_xml = false) ⇒ Odfl

:notnew: stops RDoc from seeing the initialize method



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/odfl.rb', line 62

def initialize(log = false, log_level= :debug, pretty_print_xml = false) #:notnew: stops RDoc from seeing the initialize method
  @client = Savon.client(wsdl: 'https://www.odfl.com/wsRate_v3/services/Rate?wsdl', ssl_verify_mode: :none,
                          log: log, log_level: log_level, pretty_print_xml: pretty_print_xml)
  self.freight = Array.new
  self.accessorials = Array.new
  self.tariff = 559
  self.currencyFormat = "USD"
  self.requestReferenceNumber = false
  self.weightUnits = "LBS"
  self.sendEmailOffers = false
end

Instance Attribute Details

#accessorialsObject

Returns the value of attribute accessorials.



9
10
11
# File 'lib/odfl.rb', line 9

def accessorials
  @accessorials
end

#clientObject

Returns the value of attribute client.



9
10
11
# File 'lib/odfl.rb', line 9

def client
  @client
end

#codAmountObject (readonly)

Returns the value of attribute codAmount.



6
7
8
# File 'lib/odfl.rb', line 6

def codAmount
  @codAmount
end

#cubicUnitsObject (readonly)

Returns the value of attribute cubicUnits.



6
7
8
# File 'lib/odfl.rb', line 6

def cubicUnits
  @cubicUnits
end

#currencyFormatObject

Returns the value of attribute currencyFormat.



9
10
11
# File 'lib/odfl.rb', line 9

def currencyFormat
  @currencyFormat
end

#deliveryDateTimeObject (readonly)

Returns the value of attribute deliveryDateTime.



6
7
8
# File 'lib/odfl.rb', line 6

def deliveryDateTime
  @deliveryDateTime
end

#destinationCountryObject (readonly)

Returns the value of attribute destinationCountry.



6
7
8
# File 'lib/odfl.rb', line 6

def destinationCountry
  @destinationCountry
end

#destinationPostalCodeObject (readonly)

Returns the value of attribute destinationPostalCode.



6
7
8
# File 'lib/odfl.rb', line 6

def destinationPostalCode
  @destinationPostalCode
end

#emailObject

Customer Email Address



55
56
57
# File 'lib/odfl.rb', line 55

def email
  @email
end

#firstNameObject

Customers first and last name



60
61
62
# File 'lib/odfl.rb', line 60

def firstName
  @firstName
end

#freightObject

Returns the value of attribute freight.



9
10
11
# File 'lib/odfl.rb', line 9

def freight
  @freight
end

#insuranceAmountObject

Insurance amount Required for IND or INH accessorials



51
52
53
# File 'lib/odfl.rb', line 51

def insuranceAmount
  @insuranceAmount
end

#lastNameObject

Customers first and last name



60
61
62
# File 'lib/odfl.rb', line 60

def lastName
  @lastName
end

#linearFeetObject

Set the linear feet Required for tariff 698- Security Divider



38
39
40
# File 'lib/odfl.rb', line 38

def linearFeet
  @linearFeet
end

#loosePiecesObject

Number of Loose Pieces



53
54
55
# File 'lib/odfl.rb', line 53

def loosePieces
  @loosePieces
end

#mexicoServiceCenterObject

Mexico Service Center Use for shipments to and from mexico

Acceptable values

  • TUS Tulsa AZ

  • LRD Laredo TX



29
30
31
# File 'lib/odfl.rb', line 29

def mexicoServiceCenter
  @mexicoServiceCenter
end

#movementObject

1 Character Alpha Either O (outbound) or I (inbound). Defaults to “O”



12
13
14
# File 'lib/odfl.rb', line 12

def movement
  @movement
end

#numberStackablePalletsObject

Number of stackable pallets



40
41
42
# File 'lib/odfl.rb', line 40

def numberStackablePallets
  @numberStackablePallets
end

#odfl4MePasswordObject

Required for ODFL Customer Account Pricing



14
15
16
# File 'lib/odfl.rb', line 14

def odfl4MePassword
  @odfl4MePassword
end

#odfl4MeUserObject

Required for ODFL Customer Account Pricing



14
15
16
# File 'lib/odfl.rb', line 14

def odfl4MeUser
  @odfl4MeUser
end

#odflCustomerAccountObject

Required for ODFL Customer Account Pricing



14
15
16
# File 'lib/odfl.rb', line 14

def odflCustomerAccount
  @odflCustomerAccount
end

#originCountryObject (readonly)

Returns the value of attribute originCountry.



6
7
8
# File 'lib/odfl.rb', line 6

def originCountry
  @originCountry
end

#originPostalCodeObject (readonly)

Returns the value of attribute originPostalCode.



6
7
8
# File 'lib/odfl.rb', line 6

def originPostalCode
  @originPostalCode
end

#pickupDateTimeObject (readonly)

Returns the value of attribute pickupDateTime.



6
7
8
# File 'lib/odfl.rb', line 6

def pickupDateTime
  @pickupDateTime
end

#requestObject

Returns the value of attribute request.



9
10
11
# File 'lib/odfl.rb', line 9

def request
  @request
end

#requestReferenceNumberObject

Get a reference number for the current quote request Only use if you are actually planning to ship



32
33
34
# File 'lib/odfl.rb', line 32

def requestReferenceNumber
  @requestReferenceNumber
end

#responseObject

Returns the value of attribute response.



9
10
11
# File 'lib/odfl.rb', line 9

def response
  @response
end

#resultHashObject (readonly)

Returns the value of attribute resultHash.



6
7
8
# File 'lib/odfl.rb', line 6

def resultHash
  @resultHash
end

#sendEmailOffersObject

Send email offers to customer Defaults to false



58
59
60
# File 'lib/odfl.rb', line 58

def sendEmailOffers
  @sendEmailOffers
end

#shipTypeObject

Shipment Type Defaults to LTL with optional guaranteed returned

Acceptable Values

  • LTL Standard LTL rate only returned

  • GTD Guaranteed rate only returned

  • GTO Expedited delivery rate returned (requires pickup and delivery date/time)



48
49
50
# File 'lib/odfl.rb', line 48

def shipType
  @shipType
end

#tariffObject

Tariff Code for Quote Request Defaults to 559

Acceptable values

  • 559 Standard LTL (default)

  • 698 Security Divider- Requires Linear Feet

  • 688 Household Services Home Move



22
23
24
# File 'lib/odfl.rb', line 22

def tariff
  @tariff
end

#totalCubicVolumeObject (readonly)

Returns the value of attribute totalCubicVolume.



6
7
8
# File 'lib/odfl.rb', line 6

def totalCubicVolume
  @totalCubicVolume
end

#weightUnitsObject

Set the weight units Defaults to LBS for pounds



35
36
37
# File 'lib/odfl.rb', line 35

def weightUnits
  @weightUnits
end

Instance Method Details

#addAccessorial(accessorial) ⇒ Object

Allows the user to add additional services also called accessorials

Valid Options

  • ARN Arrival Notification

  • HYD Lift Gate Service

  • COD COD - Requires COD Amount

  • CA Appointment

  • IND Insurance- Requires Insurance Amount

  • IDC Inside Pickup/Delivery

  • OVL Overlength Article- 12’ but less than 20’

  • RDC Residential/Non-Commercial Pickup/Delivery

  • CSD Construction Site Pickup/Delivery

  • CDC Schools, Colleges, Churches Pickup/Delivery

  • LDC Secured or Limited Access Pickup/Delivery

  • SWD Self Storage Delivery

  • PFF Protect From Freezing

  • HAZ Hazardous Material

  • OV2 Overlength Article - 20’ to 28’

  • DSM Delivery Service to Mines

  • HSO Scale Tickets Per Military Move (Home Moves Only)

  • INH Home Move Insurance (Home Moves Only)

Usage

quote = Odfl.new
quote.addAccessorial("HYD")


148
149
150
151
152
# File 'lib/odfl.rb', line 148

def addAccessorial(accessorial)
  if !self.accessorials.include?(accessorial)
    self.accessorials.push(accessorial)
  end
end

#addFreight(pallet) ⇒ Object

Adds freight items to the current quote Note: Either before or during the addFreight call you must call the to_hash method on the freight object

Usage

quote = Odfl.new
quote.addFreight(pallet.to_hash)


119
120
121
# File 'lib/odfl.rb', line 119

def addFreight(pallet)
  self.freight.push(pallet)
end

#get_errorObject

Return the error message if any messages exist Returns false if no error exist



291
292
293
294
295
296
297
298
# File 'lib/odfl.rb', line 291

def get_error
  error = @resultHash[:error_messages]
  if !error.nil?
    error[:string]
  else
    false
  end
end

#get_estimateObject

Return the estimate information



285
286
287
# File 'lib/odfl.rb', line 285

def get_estimate
  @resultHash[:rate_estimate]
end

#get_ratesObject

Runs the rate request

Usage

quote = Odfl.new assuming all other data has been correctly input quote.get_rates

Return Values

true if quote was successfully generated call quote.get_estimate for the actual estimate information false if there was an error call quote.get_error for the error message



229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
# File 'lib/odfl.rb', line 229

def get_rates
  @response = @client.call(:get_rate_estimate, message: { originPostalCode: @originPostalCode,
                                                          originCountry: @originCountry,
                                                          destinationPostalCode: @destinationPostalCode,
                                                          destinationCountry: @destinationCountry,
                                                          odfl4MeUser: self.odfl4MeUser,
                                                          odfl4MePassword: self.odfl4MePassword,
                                                          odflCustomerAccount: self.odflCustomerAccount,
                                                          tariff: self.tariff,
                                                          movement: self.movement,
                                                          mexicoServiceCenter: self.mexicoServiceCenter,
                                                          currencyFormat: self.currencyFormat,
                                                          requestReferenceNumber: self.requestReferenceNumber,
                                                          freightItems: {
                                                              "Freight" => self.freight
                                                          },
                                                          weightUnits: self.weightUnits,
                                                          numberPallets: self.freight.count,
                                                          linearFeet: self.linearFeet,
                                                          accessorials: {
                                                              string: self.accessorials
                                                          },
                                                          totalCubicVolume: @totalCubicVolume,
                                                          cubicUnits: @cubicUnits,
                                                          numberStackablePallets: self.numberStackablePallets,
                                                          pickupDateTime: @pickupDateTime,
                                                          deliveryDateTime: @deliveryDateTime,
                                                          shipType: self.shipType,
                                                          codAmount: @codAmount,
                                                          insuranceAmount: self.insuranceAmount,
                                                          loosePieces: self.loosePieces,
                                                          email: self.email,
                                                          sendEmailOffers: self.sendEmailOffers,
                                                          firstName: self.firstName,
                                                          lastName: self.lastName
                                             })
  processResult(@response)

  if @resultHash[:success] == '1'
    true
  else
    false
  end
end

#getDestinationServiceCenterObject

Return the destination service center information



280
281
282
# File 'lib/odfl.rb', line 280

def getDestinationServiceCenter
  @resultHash[:destination_service_center]
end

#getOriginatingServiceCenterObject

Return the originating service center information



275
276
277
# File 'lib/odfl.rb', line 275

def getOriginatingServiceCenter
  @resultHash[:originating_service_center]
end

#set_destination(zip, country = "USA") ⇒ Object

Allows the user to set the destination zip and country of the shipment

Attributes

  • zip - the zip code of the shipment destination

  • country - the country of the shipment destination defaults to USA

Usage

  1. Example Usage 1

quote = Odfl.new
quote.set_destination(20602)
  1. Example Usage 2

quote = Odfl.new
quote.set_destination(90210, "USA")


107
108
109
110
# File 'lib/odfl.rb', line 107

def set_destination(zip, country="USA")
  @destinationPostalCode = zip
  @destinationCountry = country
end

#set_origin(zip, country = "USA") ⇒ Object

Allows the user to set the origin zip and country of the shipment

Attributes

  • zip - the zip code of the shipment origin

  • country - the country of the shipment origin defaults to USA

Usage

  1. Example usage 2

quote = Odfl.new
quote.set_origin(20602)
  1. Example usage 2

quote = Odfl.new
quote.set_origin(90210, "USA")


88
89
90
91
# File 'lib/odfl.rb', line 88

def set_origin(zip, country = "USA")
  @originPostalCode = zip
  @originCountry = country
end

#setCODAmount(amount) ⇒ Object

Set an amount for COD This will also automatically add the COD accessorial

Attributes

  • amount The COD amount

Usage

quote = Odfl.new
quote.setCODAmount(100.53)


212
213
214
215
# File 'lib/odfl.rb', line 212

def setCODAmount(amount)
  @codAmount = amount
  self.addAccessorial('COD')
end

#setCubicVolume(totalCubicVolume, cubicUnits = "CF") ⇒ Object

Sets cubic volume for rate request

Attributes

  • totalCubicVolume - the total volume of the shipment

  • cubicUnits (optional)- the unit of measure for cubic volume defaults to CF for cubic feet

Usage

  1. Example Usage 1

quote = Odfl.new
quote.setCubicVolume(100)
  1. Example Usage 2

quote = Odfl.new
quote.setCubicVolume(100, "CF")


168
169
170
171
# File 'lib/odfl.rb', line 168

def setCubicVolume(totalCubicVolume, cubicUnits = "CF")
  @totalCubicVolume = totalCubicVolume
  @cubicUnits = cubicUnits
end

#setPickupDeliveryDateTime(month, day, year, hour, minute, type) ⇒ Object

Set the pickup date and time Required for Expedited GTO rates

Attributes

  • month Pickup/Delivery Month 1-12

  • day Pickup/Delivery Day 1-31

  • year Pickup/Delivery Year (4 digit year)

  • hour Pickup/Delivery Hour 0-23

  • minute Pickup/Delivery Minute 0-59

  • type The type of time to set either “pickup” or “delivery”

Usage

quote = Odfl.new
quote.setPickupDeliveryDateTime(12,25,2014,12,30, "delivery")


187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/odfl.rb', line 187

def setPickupDeliveryDateTime(month, day, year, hour, minute, type)
  month = month<10 ? "0#{month}" : "#{month}"
  day = day<10 ? "0#{day}" : "#{day}"
  hour = hour<10 ? "0#{hour}" : "#{hour}"
  minute = minute<10 ? "0#{minute}" : "#{minute}"
  second = '00'

  date = "#{year}-#{month}-#{day}T#{hour}:#{minute}:#{second}"

  if type == 'delivery'
    @deliveryDateTime = date
  else
    @pickupDateTime = date
  end
end