Skip to content
Maciej Mionskowski edited this page Jun 24, 2016 · 5 revisions

Orders service let's you manage Orders on your route4me account.

Creating Service

import (
	"github.com/route4me/route4me-go-sdk"
	"github.com/route4me/route4me-go-sdk/orders"
)

func main() {
	client := route4me.NewClient("your-api-key")
	service := &orders.Service{Client: client}
}

Endpoints

Adding an order

order := &orders.Order{
	Address1: "Some address",
	CachedLatitude: 48.335991,
	CachedLongitude: 31.18287,
}
newOrder, err := service.Add(order]
if err != nil {
	//handle errors
	return
}

Adding an order to the optimization's address

To add an order to optimization you have to first get the optimization and specify the OrderID parameter for the address in the received optimization. And execute UpdateOptimization afterwards.

Adding an order to the route's address

To add an order to optimization you have to first get the route and specify the OrderID parameter for the Address in the received optimization. And execute UpdateOptimization afterwards.

Getting orders

By specifying DeviceID member in Query struct you can filter orders returned.

orders, err := service.GetAll(&Query{})
if err != nil {
	//Handle error
	return
}
//do something with orders, it's a []Order

Getting an order by ID

To get a specific order you have to obtain its orderid first.

order, err := service.Get(&Query{ID: orderid})
if err != nil {
	//handle error
	return
}
//do something with the order

Getting orders by date created

orders, err := service.GetAll(&Query{DateInserted:"sdate=2016-06-10"}) //DD-MM-YYYY
if err != nil {
	//handle error
	return
}
//do something with the orders it's []Order

Getting an order by date scheduled

orders, err := service.GetAll(&Query{DateScheduled:"sdate=2016-06-10"}) //DD-MM-YYYY
if err != nil {
	//handle error
	return
}
//do something with the orders it's []Order

Getting an order by custom fields

orders, err := service.GetAll(&Query{Fields:"order_id,member_id"}) 
if err != nil {
	//handle error
	return
}
//do something with the orders it's []Order

Getting an order by query

orders, err := service.GetAll(&Query{Query:"Address here"}) 
	//handle error
	return
}
//do something with the orders it's []Order

Deleting orders

To remove a specific order you have to obtain its orderid first.

success, err := service.Delete([]uint64{orderid})
if err != nil || !success {
	//handle issues
	return
}

Updating an order

To update a specific order you have to obtain its orderid first. Update overrides the previous entry based on the aforementioned orderid.

order := //get order using Get, GetAll or constructing yourself.
contact, err := service.Update(order)
if err != nil {
	t.Error(err)
	return
}

You can look at service's test file for more implementation details.