I think you can using a WindowFunction for a DataStream, and sort the dataset in the windowFunction. Such as transfer a input(Iterable<T>) to a List<T>, and then use List<T>.sortBy(*) method to sort the input.
For example:
val ds = DataStream<T> ds.keyBy(key).window(...).apply(new WindowFunction)...
..
class WindowFunction extends WindowFunction..{
override def apply(key, window, input: Iterable[StockTransaction], out: Collector){
val listInput = input.toList.sortBy(_.col1)
....
}
}