From a quick look at the ShapeFile reading code it appears that GeoTools just reads the M value and throws it away. So it looks like what you are trying to do is impossible.
I haven't tested it but if you change line 89 to
cs.setOrdinate(0, CoordinateSequence.M, buffer.getDouble());
it should work. If you test this and it does work please make a PR for ...
You should take a closer look at all the interfaces that IFeatureLayer implements for a lot of this information. That's .NET documentation, but it will mirror Java pretty closely.
A lot of what you want is on the IGeoFeatureLayer, IDataLayer, and IFeatureLayerDefinition. I have not tested the below code, but it's basically what you want to be doing.
Using a Coordinate object throws an exception if you're trying to set its M value:
Coordinate c = new Coordinate(i*10,i*5,i);
Point p = geometryFactory.createPoint(c);
Exception in thread "main" java.lang.IllegalArgumentException: Invalid ordinate index: 3
This is because the normal Coordinate hasn't got an actual "m" value (so it would be ...
As per the answer from Vince, this is fairly easy with a library.
The Geodesic class from the geographiclib library provides a great implementation for Java (other language implementations are also available):
GeodesicData g1 = Geodesic.WGS84.Inverse(52.515343254180486, 13.384435940499088, 52.51544771840784, 13.386055994744083);
GeodesicData g2 = ...