How to create a matrix and add route layer by using another route optimization algorithm

I am new in tomtom. There is no tutorials about how to get matrix from A to B or single origin and destination route by different way points and calculate best route using my own route optimization algorithm and finally to render the shortest route. Can anyone help me.

Have you tried Waypoint Optimization?
Do you find it not optimal for your case?