Skip to content
Maciej Mionskowski edited this page Nov 1, 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

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}
	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 a route

Insert an existing order into an existing route.

package test

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}
	order := &orders.Order{
		Address1:        "Some address",
		CachedLatitude:  48.335991,
		CachedLongitude: 31.18287,
		RouteID:         "CEAA81617489EC7F8972372F6248946D",
	}
	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.

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}
	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.

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}
	order, err := service.Get(&Query{ID: orderid})
	if err != nil {
		//handle error
		return
	}
	//do something with the order
}

Getting orders by date created

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}
	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

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}
	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

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}
	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

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}
	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.

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}
	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.

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}
	order := //get order using Get, GetAll or constructing yourself.
	order.Field = "updated value"
	contact, err := service.Update(order)
	if err != nil {
		t.Error(err)
		return
	}
}

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