Of course, one obvious answer is trying out all possible permutations. I might have something slightly better. Suppose that you have a fixed order of angles. I'm not sure how to obtain that, so for the moment you may assume that an outer loop iterates over all possible permutations of these.
Now consider unit vectors oreinted according to the cumulative angle sums, i.e. pointing into the directions your line segments would for a given orientation of the first line. Each vector of unit length has one component in $x$ direction and one in $y$. For the moment assume that your task is not to maximize the distance between the endpoints, but instead the $x$ coordinate of the end point. Then it is easy to assign lengths to the segments: the larger the $x$ component of the corresponding unit vector, the larger the length you want to assign to that segment. Thus finding the best order of lengths means simply ordering both lists, the one of your directions by $x$ coordinate, and then match them one to one.
Now suppose you turn the first line segment around in positive (counter-clockwise) direction. All the unit vectors will turn as well. If their $y$ component is negative, then their $x$ component will increase, while for positive $y$ component the $x$ component will decrease. So take your list of unit vectors ordered by $x$ coordinates, and look for pairs of subsequent vectors where the smaller one is increasing but the larger one is decreasing. At some angle, the two will ahev the same length, and after that angle, their order by $x$ component will have changed. Furthermore, for some angle the segment will reach $y=0$, after which its growth direction will reverse. So you can compute a set of possible angles where something interesting will happen. Take the smalled of all these numbers, and act on the interesting event: If it was one segment becoming equal in $x$ coordinate to another, then you can swap them in the ordered list. If it is one segment changing direction, then you can use the new direction to compute the next interesting events.
In this fashion, you can treat a whole rotation of the angle configuration by considering only a finite number of events where interesting things do happen. For each resulting configuration, you can plug in your actual lengths in order of increasing $x$ components, and look at the resulting distance. The global optimum might not be reached in $x$ direction when considering only the interesting angles, but the uninteresting angles between all share the same combinations, so by taking the actual euclidean distance incuding the $y$ coordinate, the optimum will be among the assignments you tried out.
This should be shorter than trying all permutations for both angles and lengths. Not sure whether there is a better way. I'm none too happy with the performance of my approach, but as I couldn't think of a better solution yet, and as noone else has answered this question either so far, perhaps the above solution is better than none at all.